﻿using Model.Models;
using System.ComponentModel;
using System.Reflection;
using System.Security.Principal;

namespace AutoCreateCode
{
    /// <summary>
    /// 生成代码
    /// </summary>
    class Program
    {
     

        //static string PathBase = @"D:\MyProject\Net\TemplateCodeV2023\api";
        ////创建文件路径 【IService】
        //static string Path_IService = PathBase + @"\IService\";
        ////创建文件路径 【Service】
        //static string Path_Service = PathBase + @"\Service\";

        ////创建文件路径 【IRepository】
        //static string Path_IRepository = PathBase + @"\IRepository\";
        ////创建文件路径 【Repository】
        //static string Path_Repository = PathBase + @"\Repository\";

        ////创建文件路径 【Request】
        //static string Path_Request = PathBase + @"\Model\Request\XCZX\";
        ////创建文件路径 【Response】
        //static string Path_Response = PathBase + @"\Model\Response\XCZX\";

        //创建文件路径 【IService】
        static string Path_IService = @"D:\MyProject\industrial-treasure\API\IService\TableService\";
        //创建文件路径 【Service】
        static string Path_Service = @"D:\MyProject\industrial-treasure\API\Service\TableService\";

        //创建文件路径 【IRepository】
        static string Path_IRepository = @"D:\MyProject\industrial-treasure\API\IRepository\TableRepository\";
        //创建文件路径 【Repository】
        static string Path_Repository = @"D:\MyProject\industrial-treasure\API\Repository\TableRepository\";

        //创建文件路径 【Request】
        static string Path_Request = @"D:\MyProject\industrial-treasure\API\ModelDto\Request\TableDto\";
        //创建文件路径 【Response】
        static string Path_Response = @"D:\MyProject\industrial-treasure\API\ModelDto\Response\TableDto\";

        /// <summary>
        /// 需要生成代码的 模型命名空间
        /// </summary>
        static string nspace = "Model.Models.Auto";

        //过滤系统表
        //static List<string> filterList = new List<string>() { "apilog", "errorlog", "loginlog", "accountrole", "account", "menuaction", "menu", "rolemenuaction", "rolemenu", "role", "sysconfig", "wxuser" };


        static void Main(string[] args)
        {
            //使用一下 Model.dll 方便反射
            Account s = new Account();

            Console.WriteLine("生成代码中...");

            AutoIRepository();

            AutoRepository();

            AutoIService();

            AutoService();

            AutoRequest();

            AutoRequest2();

            AutoResponse();

            Console.WriteLine("代码已生成");

            Console.ReadKey();
        }

        /// <summary>
        /// 自动生成 IRepository 代码
        /// </summary>
        public static void AutoIRepository()
        {
            var list = AppDomain.CurrentDomain.GetAssemblies();
            Assembly asm = list.FirstOrDefault(x => x.FullName.Contains("Model"));
            //Type[] types = asm.GetTypes();
            var types = asm.GetTypes();

            if (types != null && types.Length > 0)
            {
                types = types.Where(a => a.IsClass && a.Namespace == nspace).ToArray();

                if (types != null && types.Length > 0)
                {
                    List<string> NameList = types.Select(a => a.Name).ToList();

                    if (NameList != null && NameList.Count > 0)
                    {
                        //循环 创建 过滤

                        foreach (var item in NameList)
                        {
                            //if (filterList.Contains(item.ToLower()))
                            //{
                            //    continue;
                            //}

                            if (!Directory.Exists(Path_IRepository))
                            {
                                Directory.CreateDirectory(Path_IRepository);
                            }
                            //if (Directory.Exists(Path_IRepository))
                            //{
                                //文件存在 就执行 否则不执行

                                string fileUrl = $"{Path_IRepository}I{item}Repository.cs";
                                if (!File.Exists(fileUrl))
                                {
                                    //不存在 创建  存在 则 跳过 
                                    FileStream fs = null;
                                    StreamWriter sw = null;
                                    try
                                    {

                                        fs = new FileStream(fileUrl, FileMode.Create, FileAccess.Write);

                                        sw = new StreamWriter(fs);

                                        #region 写入
                                        sw.WriteLine("using Model.Models;");
                                        sw.WriteLine("using System;");
                                        sw.WriteLine("using System.Collections.Generic;");
                                        sw.WriteLine("using System.Text;");

                                        sw.WriteLine("");

                                        sw.WriteLine("namespace IRepository");
                                        sw.WriteLine("{");
                                        sw.WriteLine($"     public interface I{item}Repository : IBaseRepository<{item}>");
                                        sw.WriteLine("      {");
                                        sw.WriteLine("      }");
                                        sw.WriteLine("}");
                                        #endregion

                                        sw.Close();
                                        fs.Close();
                                        fs.Dispose();

                                    }
                                    catch (Exception e)
                                    {
                                        sw.Close();
                                        fs.Close();
                                    }






                                }
                           // }
                        }

                    }
                }


            }




        }
        /// <summary>
        /// 自动生成 Repository 代码
        /// </summary>
        public static void AutoRepository()
        {

            //Assembly asm = Assembly.LoadFile(@"D:\project\net\QDBSvnNew\AddressExplain\Model\bin\Debug\netcoreapp3.1\Model.dll");

            var list = AppDomain.CurrentDomain.GetAssemblies();
            Assembly asm = list.FirstOrDefault(x => x.FullName.Contains("Model"));
            //Type[] types = asm.GetTypes();
            var types = asm.GetTypes();

            if (types != null && types.Length > 0)
            {
                types = types.Where(a => a.IsClass && a.Namespace == nspace).ToArray();

                if (types != null && types.Length > 0)
                {
                    List<string> NameList = types.Select(a => a.Name).ToList();

                    if (NameList != null && NameList.Count > 0)
                    {
                        //循环 创建 过滤

                        foreach (var item in NameList)
                        {
                            //if (filterList.Contains(item.ToLower()))
                            //{
                            //    continue;
                            //}
                            if (!Directory.Exists(Path_Repository))
                            {
                                Directory.CreateDirectory(Path_Repository);
                            }
                            //if (Directory.Exists(Path_Repository))
                            //{
                                //文件存在 就执行 否则不执行

                                string fileUrl = $"{Path_Repository}{item}Repository.cs";
                                if (!File.Exists(fileUrl))
                                {
                                    //不存在 创建  存在 则 跳过 
                                    FileStream fs = null;
                                    StreamWriter sw = null;
                                    try
                                    {

                                        fs = new FileStream(fileUrl, FileMode.Create, FileAccess.Write);

                                        sw = new StreamWriter(fs);

                                        #region 写入
                                        sw.WriteLine("using MysqlManager;");
                                        sw.WriteLine("using Common;");
                                        sw.WriteLine("using Model.Models;");
                                        sw.WriteLine("using System;");
                                        sw.WriteLine("using System.Collections.Generic;");
                                        sw.WriteLine("using System.Text;");
                                        sw.WriteLine("using IRepository;");

                                        sw.WriteLine("");
                                        sw.WriteLine("namespace Repository");
                                        sw.WriteLine("{");
                                        sw.WriteLine($"     public class {item}Repository : BaseRepository<{item}>, I{item}Repository");
                                        sw.WriteLine("      {");
                                        sw.WriteLine($"              public {item}Repository(IDbConnectionFactory DbConnectionFactory, IRedisHelper redisHelper) : base(DbConnectionFactory, redisHelper)");
                                        sw.WriteLine("              {");
                                        sw.WriteLine("");
                                        sw.WriteLine("              }");
                                        sw.WriteLine("      }");
                                        sw.WriteLine("}");
                                        #endregion

                                        sw.Close();
                                        fs.Close();
                                        fs.Dispose();

                                    }
                                    catch (Exception e)
                                    {
                                        sw.Close();
                                        fs.Close();
                                    }


                                }
                           // }
                        }

                    }
                }


            }

        }

        /// <summary>
        /// 自动生成 IService 代码
        /// </summary>
        public static void AutoIService()
        {

            //Assembly asm = Assembly.LoadFile(@"D:\project\net\QDBSvnNew\AddressExplain\Model\bin\Debug\netcoreapp3.1\Model.dll");

            var list = AppDomain.CurrentDomain.GetAssemblies();
            Assembly asm = list.FirstOrDefault(x => x.FullName.Contains("Model"));
            //Type[] types = asm.GetTypes();
            var types = asm.GetTypes();

            if (types != null && types.Length > 0)
            {
                types = types.Where(a => a.IsClass && a.Namespace == nspace).ToArray();

                if (types != null && types.Length > 0)
                {
                    List<string> NameList = types.Select(a => a.Name).ToList();

                    if (NameList != null && NameList.Count > 0)
                    {
                        //循环 创建 过滤

                        foreach (var item in NameList)
                        {
                            if (!Directory.Exists(Path_IService))
                            {
                                Directory.CreateDirectory(Path_IService);
                            }
                            //if (Directory.Exists(Path_IService))
                            //{
                                //文件存在 就执行 否则不执行

                                string fileUrl = $"{Path_IService}I{item}Service.cs";
                                if (!File.Exists(fileUrl))
                                {
                                    //不存在 创建  存在 则 跳过 
                                    FileStream fs = null;
                                    StreamWriter sw = null;
                                    try
                                    {

                                        fs = new FileStream(fileUrl, FileMode.Create, FileAccess.Write);

                                        sw = new StreamWriter(fs);

                                        #region 写入
                                        sw.WriteLine("using ModelDto;");
                                        sw.WriteLine("using Model.Models;");
                                        sw.WriteLine("using System;");
                                        sw.WriteLine("using System.Collections.Generic;");
                                        sw.WriteLine("using System.Text;");
                                        sw.WriteLine("using System.Linq.Expressions;");

                                        sw.WriteLine("");

                                        sw.WriteLine("namespace IService");
                                        sw.WriteLine("{");


                                        sw.WriteLine($"     public interface I{item}Service");
                                        sw.WriteLine("      {");

                                        sw.WriteLine($"             {item} Find(string id);");
                                        sw.WriteLine($"             {item} Query(Func<{item}, bool> whereLambda);");
                                        sw.WriteLine($"             List<{item}> QueryList(Func<{item}, bool> whereLambda);																																");
                                        sw.WriteLine($"             List<{item}> QueryList<S>(Func<{item}, bool> whereLambda, int pageIndex, int pageSize, out int totalCount, Expression<Func<{item}, S>> orderby, bool IsAsc = true) where S : class;  ");
                                        sw.WriteLine($"             {item} AddBackEntity({item} entity);");
                                        sw.WriteLine($"             bool Add({item} entity);");
                                        sw.WriteLine($"             bool Update({item} entity);");
                                        sw.WriteLine($"             bool Dellete({item} entity);");
                                        sw.WriteLine($"             bool DeleteByWhere(Func<{item}, bool> whereLambda);");
                                        sw.WriteLine($"             List<{item}> GetListCache();");



                                        sw.WriteLine("      }");



                                        sw.WriteLine("}");
                                        #endregion

                                        sw.Close();
                                        fs.Close();
                                        fs.Dispose();

                                    }
                                    catch (Exception e)
                                    {
                                        sw.Close();
                                        fs.Close();
                                    }






                                }
                           // }
                        }

                    }
                }


            }




        }
        /// <summary>
        /// 自动生成 Service 代码
        /// </summary>
        public static void AutoService()
        {

            //Assembly asm = Assembly.LoadFile(@"D:\project\net\QDBSvnNew\AddressExplain\Model\bin\Debug\netcoreapp3.1\Model.dll");

            var list = AppDomain.CurrentDomain.GetAssemblies();
            Assembly asm = list.FirstOrDefault(x => x.FullName.Contains("Model"));
            //Type[] types = asm.GetTypes();
            var types = asm.GetTypes();

            if (types != null && types.Length > 0)
            {
                types = types.Where(a => a.IsClass && a.Namespace == nspace).ToArray();

                if (types != null && types.Length > 0)
                {
                    List<string> NameList = types.Select(a => a.Name).ToList();

                    if (NameList != null && NameList.Count > 0)
                    {
                        //循环 创建 过滤

                        foreach (var item in NameList)
                        {
                            if (!Directory.Exists(Path_Service))
                            {
                                Directory.CreateDirectory(Path_Service);
                            }
                            //if (Directory.Exists(Path_Service))
                            //{
                                //文件存在 就执行 否则不执行

                                string fileUrl = $"{Path_Service}{item}Service.cs";
                                if (!File.Exists(fileUrl))
                                {
                                    //不存在 创建  存在 则 跳过 
                                    FileStream fs = null;
                                    StreamWriter sw = null;
                                    try
                                    {

                                        fs = new FileStream(fileUrl, FileMode.Create, FileAccess.Write);

                                        sw = new StreamWriter(fs);

                                        #region 写入
                                        //sw.WriteLine("using EFCore.Mysql;");
                                        sw.WriteLine("using IService;");
                                        sw.WriteLine("using Common;");
                                        sw.WriteLine("using Model.Models;");
                                        sw.WriteLine("using System;");
                                        sw.WriteLine("using System.Collections.Generic;");
                                        sw.WriteLine("using System.Text;");
                                        sw.WriteLine("using ModelDto;");
                                        sw.WriteLine("using IRepository;");
                                        sw.WriteLine("using System.Linq.Expressions;");

                                        sw.WriteLine("");
                                        sw.WriteLine("namespace Service");
                                        sw.WriteLine("{");
                                        sw.WriteLine($"     public class {item}Service : I{item}Service");
                                        sw.WriteLine("      {");






                                        sw.WriteLine($"private readonly I{item}Repository _{item}Repository;");
                                        sw.WriteLine($"public {item}Service(I{item}Repository {item}Repository)");
                                        sw.WriteLine("{");
                                        sw.WriteLine($"_{item}Repository = {item}Repository;");
                                        sw.WriteLine("}");
                                        sw.WriteLine($"public bool Add({item} entity)");
                                        sw.WriteLine("{");


                                        sw.WriteLine("if (string.IsNullOrWhiteSpace(entity.Id)){");
                                        sw.WriteLine("entity.Id = Guid.NewGuid().ToString(\"N\");");
                                        sw.WriteLine("}");

                                        //sw.WriteLine("entity.Id = Guid.NewGuid().ToString(\"N\");");

                                        sw.WriteLine("entity.IsDelete = false;");
                                        sw.WriteLine("entity.UpdateUser = \"\";");
                                        sw.WriteLine("entity.DeleteUser = \"\";");


                                        sw.WriteLine($"return _{item}Repository.Add(entity);");
                                        sw.WriteLine("}");
                                        sw.WriteLine($"public {item} AddBackEntity({item} entity)");
                                        sw.WriteLine("{");
                                        sw.WriteLine($"return _{item}Repository.AddBackEntity(entity);");
                                        sw.WriteLine("}");
                                        sw.WriteLine($"public bool Update({item} entity)");
                                        sw.WriteLine("{");
                                        sw.WriteLine($"return _{item}Repository.Update(entity);");
                                        sw.WriteLine("}");
                                        sw.WriteLine($"public bool DeleteByWhere(Func<{item}, bool> whereLambda) ");
                                        sw.WriteLine("{ ");
                                        sw.WriteLine($"return _{item}Repository.DeleteByWhere(whereLambda); ");
                                        sw.WriteLine("}");
                                        sw.WriteLine($"public bool Dellete({item} entity)");
                                        sw.WriteLine("{ ");
                                        sw.WriteLine($"return _{item}Repository.Dellete(entity); ");
                                        sw.WriteLine("} ");
                                        sw.WriteLine($"public {item} Find(string id)");
                                        sw.WriteLine("{");
                                        sw.WriteLine($"return _{item}Repository.Find(id);");
                                        sw.WriteLine("}");
                                        sw.WriteLine($"public List<{item}> GetListCache()");
                                        sw.WriteLine("{ ");
                                        sw.WriteLine($"return _{item}Repository.GetListCache();");
                                        sw.WriteLine("}");
                                        sw.WriteLine($"public {item} Query(Func<{item}, bool> whereLambda) ");
                                        sw.WriteLine("{");
                                        sw.WriteLine($"return _{item}Repository.Query(whereLambda); ");
                                        sw.WriteLine("}");
                                        sw.WriteLine($"public List<{item}> QueryList(Func<{item}, bool> whereLambda)  ");
                                        sw.WriteLine("{  ");
                                        sw.WriteLine($"return _{item}Repository.QueryList(whereLambda);  ");
                                        sw.WriteLine("}");
                                        sw.WriteLine($"public List<{item}> QueryList<S>(Func<{item}, bool> whereLambda, int pageIndex, int pageSize, out int totalCount, Expression<Func<{item}, S>> orderby, bool IsAsc = true) where S : class     ");
                                        sw.WriteLine("{ ");
                                        sw.WriteLine($"totalCount = 0;");
                                        sw.WriteLine($"return _{item}Repository.QueryList(whereLambda, pageIndex, pageSize,out totalCount, orderby, IsAsc);    ");
                                        sw.WriteLine("}");












                                        sw.WriteLine("      }");
                                        sw.WriteLine("}");
                                        #endregion

                                        sw.Close();
                                        fs.Close();
                                        fs.Dispose();

                                    }
                                    catch (Exception e)
                                    {
                                        sw.Close();
                                        fs.Close();
                                    }


                                }
                            //}
                        }

                    }
                }


            }

        }

        /// <summary>
        /// 自动生成 Request 代码
        /// </summary>
        public static void AutoRequest()
        {

            //Assembly asm = Assembly.LoadFile(@"D:\project\net\QDBSvnNew\AddressExplain\Model\bin\Debug\netcoreapp3.1\Model.dll");

            var list = AppDomain.CurrentDomain.GetAssemblies();
            Assembly asm = list.FirstOrDefault(x => x.FullName.Contains("Model"));
            //Type[] types = asm.GetTypes();
            var types = asm.GetTypes();

            if (types != null && types.Length > 0)
            {
                types = types.Where(a => a.IsClass && a.Namespace == nspace).ToArray();

                if (types != null && types.Length > 0)
                {
                    //获取属性
                    foreach (var type in types)
                    {
                        PropertyInfo[] properties = type.GetProperties();

                        if (!Directory.Exists(Path_Request))
                        {
                            Directory.CreateDirectory(Path_Request);
                        }

                        if ( properties != null && properties.Length > 0)
                        {
                            string fileUrl = $"{Path_Request}{type.Name}Request.cs";
                            if (!File.Exists(fileUrl))
                            {
                                FileStream fs = null;
                                StreamWriter sw = null;
                                try
                                {
                                    fs = new FileStream(fileUrl, FileMode.Create, FileAccess.Write);

                                    sw = new StreamWriter(fs);

                                    #region 写入
                                    sw.WriteLine("using System;");
                                    sw.WriteLine("using System.Collections.Generic;");
                                    sw.WriteLine("using System.Text;");

                                    sw.WriteLine("");
                                    sw.WriteLine("namespace ModelDto");
                                    sw.WriteLine("{");

                                    sw.WriteLine($"     public  class {type.Name}Request");
                                    sw.WriteLine("      {");

                                    foreach (PropertyInfo propertyInfo in properties)
                                    {


                                        string name = propertyInfo.Name;
                                        var typenameCurrent = propertyInfo.PropertyType.Name;
                                        string tempStr = name.ToLower();

                                        List<string> nonames = new List<string>() {
                                           "createtime","updatetime","deletetime","createuser","updateuser","deleteuser","isdelete"
                                        };
                                        if (!nonames.Contains(tempStr))
                                        {
                                            string typeName = TypeStr(typenameCurrent);

                                            string discriptionStr = "";
                                            object[] obj = propertyInfo.GetCustomAttributes(typeof(DescriptionAttribute), true);
                                            foreach (DescriptionAttribute desc in obj)
                                            {
                                                discriptionStr = desc.Description;
                                            }

                                            sw.WriteLine("          /// <summary>");
                                            sw.WriteLine($"         /// {discriptionStr}");
                                            sw.WriteLine("          /// </summary>");
                                            sw.WriteLine("          public " + typeName + " " + name + " { get; set; }");
                                            sw.WriteLine("");

                                        }


                                    }


                                    sw.WriteLine("      }");

                                    sw.WriteLine("}");
                                    #endregion

                                    sw.Close();
                                    fs.Close();
                                    fs.Dispose();

                                }
                                catch (Exception e)
                                {
                                    sw.Close();
                                    fs.Close();
                                }
                            }
                        }


                    }


                }


            }

        }

        /// <summary>
        /// 自动生成 Request 代码
        /// </summary>
        public static void AutoRequest2()
        {

            //Assembly asm = Assembly.LoadFile(@"D:\project\net\QDBSvnNew\AddressExplain\Model\bin\Debug\netcoreapp3.1\Model.dll");

            var list = AppDomain.CurrentDomain.GetAssemblies();
            Assembly asm = list.FirstOrDefault(x => x.FullName.Contains("Model"));
            //Type[] types = asm.GetTypes();
            var types = asm.GetTypes();

            if (types != null && types.Length > 0)
            {
                types = types.Where(a => a.IsClass && a.Namespace == nspace).ToArray();

                if (types != null && types.Length > 0)
                {
                    //获取属性
                    foreach (var type in types)
                    {
                        PropertyInfo[] properties = type.GetProperties();


                        if (!Directory.Exists(Path_Request))
                        {
                            Directory.CreateDirectory(Path_Request);
                        }

                        if ( properties != null && properties.Length > 0)
                        {
                            string fileUrl = $"{Path_Request}{type.Name}RequestPage.cs";
                            if (!File.Exists(fileUrl))
                            {
                                FileStream fs = null;
                                StreamWriter sw = null;
                                try
                                {
                                    fs = new FileStream(fileUrl, FileMode.Create, FileAccess.Write);

                                    sw = new StreamWriter(fs);

                                    #region 写入
                                    sw.WriteLine("using System;");
                                    sw.WriteLine("using System.Collections.Generic;");
                                    sw.WriteLine("using System.Text;");

                                    sw.WriteLine("");
                                    sw.WriteLine("namespace ModelDto");
                                    sw.WriteLine("{");

                                    sw.WriteLine($"     public  class {type.Name}RequestPage: PageBaseRequest");
                                    sw.WriteLine("      {");


                                    sw.WriteLine("      }");

                                    sw.WriteLine("}");
                                    #endregion

                                    sw.Close();
                                    fs.Close();
                                    fs.Dispose();

                                }
                                catch (Exception e)
                                {
                                    sw.Close();
                                    fs.Close();
                                }
                            }
                        }


                    }


                }


            }

        }

        /// <summary>
        /// 自动生成 Response 代码
        /// </summary>
        public static void AutoResponse()
        {

            //Assembly asm = Assembly.LoadFile(@"D:\project\net\QDBSvnNew\AddressExplain\Model\bin\Debug\netcoreapp3.1\Model.dll");

            var list = AppDomain.CurrentDomain.GetAssemblies();
            Assembly asm = list.FirstOrDefault(x => x.FullName.Contains("Model"));
            //Type[] types = asm.GetTypes();
            var types = asm.GetTypes();

            if (types != null && types.Length > 0)
            {
                types = types.Where(a => a.IsClass && a.Namespace == nspace).ToArray();

                if (types != null && types.Length > 0)
                {
                    //获取属性
                    foreach (var type in types)
                    {
                        PropertyInfo[] properties = type.GetProperties();

                        if (!Directory.Exists(Path_Response))
                        {
                            Directory.CreateDirectory(Path_Response);
                        }

                        if (properties != null && properties.Length > 0)
                        {
                            string fileUrl = $"{Path_Response}{type.Name}Response.cs";
                            if (!File.Exists(fileUrl))
                            {
                                FileStream fs = null;
                                StreamWriter sw = null;
                                try
                                {
                                    fs = new FileStream(fileUrl, FileMode.Create, FileAccess.Write);

                                    sw = new StreamWriter(fs);

                                    #region 写入
                                    sw.WriteLine("using System;");
                                    sw.WriteLine("using System.Collections.Generic;");
                                    sw.WriteLine("using System.Text;");

                                    sw.WriteLine("");
                                    sw.WriteLine("namespace ModelDto");
                                    sw.WriteLine("{");

                                    sw.WriteLine($"     public  class {type.Name}Response");
                                    sw.WriteLine("      {");

                                    foreach (PropertyInfo propertyInfo in properties)
                                    {
                                        string name = propertyInfo.Name;
                                        var typenameCurrent = propertyInfo.PropertyType.Name;
                                        string tempStr = name.ToLower();

                                        List<string> nonames = new List<string>() {
                                            "updatetime","deletetime","createuser","updateuser","deleteuser","isdelete"
                                        };
                                        if (!nonames.Contains(tempStr))
                                        {
                                            string typeName = TypeStr(typenameCurrent);

                                            string discriptionStr = "";
                                            object[] obj = propertyInfo.GetCustomAttributes(typeof(DescriptionAttribute), true);
                                            foreach (DescriptionAttribute desc in obj)
                                            {
                                                discriptionStr = desc.Description;
                                            }

                                            sw.WriteLine("          /// <summary>");
                                            sw.WriteLine($"         /// {discriptionStr}");
                                            sw.WriteLine("          /// </summary>");
                                            sw.WriteLine("          public " + typeName + " " + name + " { get; set; }");
                                            sw.WriteLine("");

                                        }


                                    }


                                    sw.WriteLine("      }");

                                    sw.WriteLine("}");
                                    #endregion

                                    sw.Close();
                                    fs.Close();
                                    fs.Dispose();

                                }
                                catch (Exception e)
                                {
                                    sw.Close();
                                    fs.Close();
                                }
                            }
                        }


                    }


                }


            }

        }

        /// <summary>
        /// 返回类型
        /// </summary>
        /// <returns></returns>
        private static string TypeStr(string typestr)
        {
            if (typestr == "Decimal")
            {
                return "decimal";
            }
            else if (typestr == "String")
            {
                return "string";
            }
            else if (typestr == "Boolean")
            {
                return "bool";
            }
            else if (typestr == "Int32")
            {
                return "int";
            }
            else if (typestr == "DateTime")
            {
                return "DateTime";
            }
            else if (typestr == "nullable`1")
            {
                return "DateTime?";
            }
            else
            {
                return "DateTime?";
            }
        }
    }
}